package com.sgcc.ln.pmos.e_ln_mall.presenter;

import com.sgcc.ln.pmos.common.base.BasePresenter;
import com.sgcc.ln.pmos.common.http.HttpInterConst;
import com.sgcc.ln.pmos.common.http.HttpRequestUtils;
import com.sgcc.ln.pmos.common.http.MvpNetCallback;
import com.sgcc.ln.pmos.common.utils.ListPageUtil;
import com.sgcc.ln.pmos.e_ln_mall.bean.MallGoodsBean;
import com.sgcc.ln.pmos.e_ln_mall.contract.AllGoodsContract;

import java.util.HashMap;
import java.util.Map;

import okhttp3.Call;

public class AllGoodsPresenter extends BasePresenter<AllGoodsContract.View> implements AllGoodsContract.Presenter{
    /**
     * 商品列表
     *
     * @param pageSize
     * @param isLoading
     */
    @Override
    public void getGoodsList(String membersSdId,int pageSize, boolean isLoading) {
        Map<String, Object> params = new HashMap<>();
        params.putAll(ListPageUtil.getPageInfo(pageSize));
        params.put("combName", "");
        params.put("membersSdId", membersSdId);
        params.put("sort", "");
        params.put("soldEnergySort", "");
        params.put("avgPriceSort", "");
        params.put("createDateSort", "");
        Map<String, Object> params1 = new HashMap<>();
        params.put("packageInfoCombVo", params1);
        params.put("_t", System.currentTimeMillis());
        HttpRequestUtils.getInstance().request(params, HttpInterConst.HOME_PACKAGE, new MvpNetCallback<MallGoodsBean>(getView(), true) {
            @Override
            public void onError(Call call, Exception e, int id) {
                super.onError(call, e, id);
                if (!isViewAttached()) {
                    return;
                }
                // 失败回调 判断界面是否销毁
                getView().queryGoodsListFailed();
            }

            @Override
            public void onResponse(MallGoodsBean response, int id) {
                super.onResponse(response, id);
                if (!isViewAttached()) {
                    return;
                }
                getView().queryGoodsListSuccess(response);
            }
        });
    }
}
